package com.taxinfo.controller;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.taxinfo.pojo.vo.DecDocumentRec;
import com.taxinfo.service.DecDocumentRecService;
import com.taxinfo.utils.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.Map;

@RequestMapping("/api")
@RestController
public class OutCallApiController {

    @Autowired
    private DecDocumentRecService decDocumentRecService;

    @PostMapping(value = "/notification", consumes = "application/json")
    public String notification(@RequestBody Map<String,String> params){
        String id = params.get("data");
        if(StringUtils.isBlank(id)){
            return "2"; //参数ID不能为空
        }
        //更新处理
        DecDocumentRec documentRec =  decDocumentRecService.getBaseMapper().selectById(id);
        if(null == documentRec ){
            return "2"; //文件参数ID不存在
        }
        String status = params.get("status");
        String message ="";
        if("200".equals(status)){
            message = "机器人申报处理成功。";
            documentRec.setIsSb("已申报");
        }else{
            message = "机器人申报处理失败！";
        }

        documentRec.setSbMsg(message);
        documentRec.setSbTime(DateUtil.formatDate(new Date(),"yyyy-MM-dd HH:mm:ss"));
        boolean blnflg = decDocumentRecService.updateById(documentRec);
        // 处理成功的推送
        if(blnflg){
            return "0"; //处理成功
        }else{
            return "1"; //处理失败
        }
    }
}
